// 全局apiurl
// var urlpath = location.href.indexOf("?")+1;
// urlpath = location.href.substring(urlpath);
// var arr=urlpath.split("&");
// uesrMessage ={
// }
// arr.forEach(
//     function(item){
//         var brr = [];
//         brr=item.split("=");
//         debugger;
//         x[brr[0]]= brr[1];
//     }
// )
// var  userId = uesrMessage.userId;
// var  bzId = uesrMessage.bzId;

// var baseUrl  = "http://10.36.1.67/bzapp/";
// var userId = ;
// var bzId = bzId;

var urlpath = location.href.indexOf("?")+1;
urlpath = location.href.substring(urlpath);
var arr=urlpath.split("&");
var userId = ''
var bzId = ''
arr.forEach(
    function(item){
        var brr = [];
        brr=item.split("=");
        // [brr[0]]= brr[1];
        if(brr[0] == 'userId'){
            userId = brr[1]
        }else if(brr[0] == 'bzId'){
            bzId = brr[1]
        }
        console.log(brr)
    }    
)
console.log(userId,bzId)


var peopleList = [];
//获取班组简介
var fd = new FormData();
fd.append("json",JSON.stringify({
    "userId":userId,
    // "userId":'b070e77e-2289-4b58-979b-2db72d42f9a4',
    "data":{
        "bzId":bzId
        // "bzId":'feae4a0f-5cac-4f03-9bca-bcfa099b54f8'
    }
}));
// 人员简介字段渲染

$.ajax(
    {
        url:baseUrl+'api/Culture/GetMeetAbstract',
        data:{
            json:JSON.stringify({
                "userId":userId,
                // "userId":'b070e77e-2289-4b58-979b-2db72d42f9a4',
                "data":{
                    "bzId":bzId
                    // "bzId":'feae4a0f-5cac-4f03-9bca-bcfa099b54f8'
                }
            })
        },
        type:"POST",
        // contentType:false,
        // processData:false,
        success:function(data){
            console.log(data);
            if(data.code==0){
                classinstru(data.data)
                $(".topLeft").html(data.data.BzName);
            }
            
        }
    }
)
function classinstru(item){
    var x ='<li>班组成员'+item.Member+'人</li><li>工程师'+item.Engineer+'人</li><li>技师'+item.Technician+'人</li>'+
    '<li>大专及以上学历'+item.Education+'人</li><li>助理工程师'+item.AssistantEngineer+'人</li><li>高级工'+item.Expert+'人</li>'+
    '<li>中共党员'+item.PartyMember+'人</li><li>高级技师'+item.ExpertTechnician+'人</li><li>平均年龄'+(Number(item.AverageAage)).toFixed(0)+'岁</li>'
   $("#m-job").html(x);
}
//获取文化墙信息
$.ajax(
    {
        // contentType:"application/json; charset=utf-8",
        url:baseUrl+'api/Culture/GetWallInfo',
        data:fd,
        type:"POST",
        contentType:false,
        processData:false,
        success:function(data){
            if(data.code==0){
                mainclass(data.data);
                // $(".topLeft").html(data.data.BzName);
            }
        }
    }
)
function mainclass(item){
    $("#textareaW").html(item.summary);
    // $("#classhope").val('是滴是滴')
    $("#classhope").val(item.vision);
    // console.log(document.getElementById("#classhop"))
    // document.getElementById("#classhop").innerHTML="11111"
     if(item.slogan){
                var xstring = item.slogan;
                if(xstring.length>20){
                   xstring =  xstring.substring(0,20)+"...";
                }
                $(".titlep").html(xstring);
        }
    var arr =[];//班组荣誉
    var brr = [];//风采剪影
    item.pics.forEach(
        function(obj){
            if(obj.filetype==1){
                arr.push(obj);
            }else{
                brr.push(obj);
            }
        }
    )
    console.log(arr,brr);
    var arrObj = "";
    var brrObj = "";
    if(arr.length>4){
        arr = arr.slice(0,4);
    }
    console.log(arr);
    for(var j=0;j<arr.length;j++){
        arrObj +='<img src="'+arr[j].filepath+'" alt="">'
    }

    $(".honour").html(arrObj);
    if(brr.length>3){
        brr = brr.slice(0,3);
    }
    for(var h=0;h<brr.length;h++){
        brrObj += '<img src="'+brr[h].filepath+'" alt="">'
    }
    $(".face").html(brrObj);
}
//保存、编辑文化墙信息
var SaveWallInfo = new FormData();
var saveParams ={
       userId:userId,
    // userId:'b070e77e-2289-4b58-979b-2db72d42f9a4',
       data:{
        bzId:bzId,
        // bzId:'feae4a0f-5cac-4f03-9bca-bcfa099b54f8',
        summary:"aaaaa",
        concept:"dssssssssssssssssssssss",
        slogan:"bbbbb",
        vision:"cccc"
       } 
}
SaveWallInfo.append(
    'json',JSON.stringify(saveParams)
)
$.ajax(
    {
        url:baseUrl+'api/Culture/SaveWallInfo',
        data:SaveWallInfo,
        type:"POST",
        contentType:false,
        processData:false,
        success:function(data){
            console.log(data);
        }
    }
)
//上传风采剪影、班组荣誉
var UpdateFile = new FormData();
var UpdateFileInfo ={
       userId:userId,
    // userId:'b070e77e-2289-4b58-979b-2db72d42f9a4',    
       data:{
        bzId:bzId,
        // bzId:'feae4a0f-5cac-4f03-9bca-bcfa099b54f8',        
        deletefileids:"",
        description:"",
        filetype:"0",
       } 
}
UpdateFile.append(
    'json',JSON.stringify(UpdateFileInfo)
)
$.ajax(
    {
        url:baseUrl+'api/Culture/UploadFile',
        data:UpdateFile,
        type:"POST",
        contentType:false,
        processData:false,
        success:function(data){
            console.log(data);
        }
    }
)
//获取班组成员
var classpeople = new FormData();
$.ajax(
    {
        url:baseUrl+'api/Culture/GetDeptMembers',
        type:"POST",
        data:{
            json:JSON.stringify({
                "userId":userId,
                // "userId":'b070e77e-2289-4b58-979b-2db72d42f9a4',
                "data":{
                    "bzId":bzId
                    // "bzId":'feae4a0f-5cac-4f03-9bca-bcfa099b54f8'
                }
            })
        },
        success:function(data){
            if(data.code==0){
                peopleList = data.data.slice(0,6);
                getperson();
            }
            console.log(peopleList);
            // peopleList = 
        }
    }
)
function getperson(){
    var x = "";
    for(var i=0;i<peopleList.length;i++){
          x +=  '<li>'+
                    '<img src="'+(peopleList[i].Photo?peopleList[i].Photo:'./img/02/person.png')+'" alt="" />'+
                    '<div>'+
                        '<h4>'+peopleList[i].Name+'</h4>'+
                        '<p>'+peopleList[i].Quarters+'</p>'+
                    '</div>'+
                '</li>'
    }
    $("#peopleQ").html(x);
}
//月度工作任务评分
// $.ajax(
//     {
//         url:baseUrl+'api/Culture/GetMonthScore',
//         data:{json:JSON.stringify(
//             {
//                 "userId":userId,
//                 "data":{
//                     "year":year,
//                     "month":month
//                 }
//             }
//         )},
//         type:"POST",
//         // contentType:false,
//         // processData:false,
//         success:function(data){
//         }
//     }
// )

//获取班组月考勤数据
// $.ajax(
//     {
//         url:baseUrl+'api/Attendance/GetDeptAttendance',
//         data:{json:JSON.stringify(
//             {
//                 "userId":userId,
//                 // "userId":'b070e77e-2289-4b58-979b-2db72d42f9a4',
//                 "data":{
//                     "year":year,
//                     "month":month
//                 }
//             }
//         )},
//         type:"POST",
//         // contentType:false,
//         // processData:false,
//         success:function(data){
//             studyDate(data.data)
//         }
//     }
// )

function studyDate(list){
    var arrlist = ""
    for(var i=0;i<list.length;i++){
        arrlist +='<div class="c-c-listmsg">'+
            '<div class="tv-title">'+
                '<div class="tv-img">'+
                    '<img src="'+list[i].Photo+'" alt="">'+
                '</div>'+
                '<div class="t-v-v">'+
                    '<div class="t-name">'+list[i].UserName+'</div>'+
                    '<div class="t-job-t">标准化管理员</div>'+
                '</div>'+
            '</div>'
            for(var j=0;j<list[i]['Data'].length;j++){
                if(list[i]['Data'][j].Category=="值班"||list[i]['Data'][j].Category=="出勤"){
                    arrlist += '<div class="to-works">'+
                    '<div class="page-number bg-color-font">'+list[i]['Data'][j].Times+'</div>'+
                    '<div class="page-num">值班(次)</div>'+
                    '</div>'
                }else{
                    arrlist += '<div class="to-works">'+
                    '<div class="page-number bg-color-font">'+list[i]['Data'][j].Hours+'</div>'+
                    '<div class="page-num">值班(h)</div>'+
                    '</div>'
                }
            }
            arrlist +='</div>'
    }
    $("#morework").html(arrlist);
}
//值班表
var DateTime = new Date();
var year =  DateTime.getFullYear();
var month = DateTime.getMonth()+1;
var from = year+"-"+month+'-1';

var to = "";
if(month==12){
   to = (year+1)+'-1-1'
}else{
    to =year+"-"+(month+1)+'-1';
}
$.ajax(
    {
        url:baseUrl+'api/Attendance/GetDutyData',
        data:{json:JSON.stringify(
            {
                "userId":userId,
                // "userId":'b070e77e-2289-4b58-979b-2db72d42f9a4',
                "data":{
                    "from":year+"-"+month+'-1',
                    "to":to
                }
            }
        )},
        type:"POST",
        // contentType:false,
        // processData:false,
        success:function(data){
            var datapeople = data.data.pop();
            var xinqi = DateTime.getDay();
            var dateArr = [];
            data.data.forEach(
               function(item,index){
                 dateArr.push(
                     {
                        Data: item.Data,
                        index: index+1
                     }
                 )
               }
            )
            work(xinqi,dateArr)
        }
    }
)
//创建值班表
function work(index,list){
    var worklist = "";
    worklist += '<tr><th>日</th><th>一</th><th>二</th><th>三</th><th>四</th><th>五</th><th>六</th></tr><tr>';
    var a = [];
    var c = [];
    var d = [];
    var DateTime = new Date();
    var day =  DateTime.getDate();
    day = day+index-1;
    


    for(var k=0;k<(index);k++){
        a.push(
            {
                Data: ""
            }
        )
    }
    c = a.concat(list);
    
    for(var w=0;w<(42-c.length)%7;w++){
        d.push(
            {
                Data: ""
            }
        )
    }
    c = c.concat(d);
    for(var q=0;q<c.length/7;q++){
        worklist += '<tr>'
        for(var o=0;o<7;o++){
            if((q*7+o)==day){
                worklist +='<td class="dayactive">'+
                '<span>'+((c[7*q+o].index)?(c[7*q+o].index):"")+'</span>'+
                '<p>'+((c[7*q+o].Data)?(c[7*q+o].Data):"")+'</p>'+
                '</td>'
            }else{
                worklist +='<td>'+
                '<span>'+((c[7*q+o].index)?(c[7*q+o].index):"")+'</span>'+
                '<p>'+((c[7*q+o].Data)?(c[7*q+o].Data):"")+'</p>'+
                '</td>'
            }
        }
        worklist += '</tr>'
    }
    $("#newtable").html(worklist);
}
//获取学习园地
$.ajax(
    {
        url:baseUrl+'api/Culture/GetLearningGardens',
        data:fd,
        type:"POST",
        contentType:false,
        processData:false,
        success:function(data){
            console.log(data);
            studyarea(data.data);
        }
    }
)
function studyarea(itemlist){
    var studyarealist = "";
    studyarealist +='<h3><i>学</i><i>习</i><i>园</i><i>地</i></h3>';
    for(var i=0;i<itemlist.length;i++){
        studyarealist +='<a class="bg-tab"  data-url="'+itemlist[i].filepath+'">'+itemlist[i].filename+'</a>';
    }
    $("#h-commoms").html(studyarealist);
    $(".bg-tab").click(
        function(){
            var urlpaths = $(this).attr('data-url');
            bzApi.downloadFile(urlpaths)
        }
    )

}

var AffairsList = [];
//获取要务公开
$.ajax({
    url: baseUrl + 'api/DepartmentPublish/List',
    data: JSON.stringify({       
        "userId": userId
            // "userId": 'b070e77e-2289-4b58-979b-2db72d42f9a4',               
    }),
    type: "POST",
    success: function (res){
        console.log(res)
        if (res.code == 0) {
            AffairsList = res.data
            PublishId = AffairsList[0].PublishId
            // debugger
            // res.data.forEach(function(item){
            //     item.Files.forEach(function(item2){
            //         debugger
            //         if(item2.Description == "照片"){
            //             affImgList.push(item2.FilePath)
            //         }else{
            //             affFileList.push(item2.FileName)
            //         }
            //     })          
            // })
            // console.log(333,AffairsList,affImgList,affFileList)
            getAffairs()
        }     
    }
})

//展示要务
function getAffairs(){
    var m = ''
    console.log(AffairsList)
    for(var i = 0;i < AffairsList.length;i++){
        var affImgList = [];
        var affFileList = [];
        AffairsList[i].Files.forEach(function(item){
            if(item.Description == "照片"){
                affImgList.push(item.FilePath)
            }else{
                var affFileObj = {};
                affFileObj.FileName = item.FileName
                affFileObj.FilePath = item.FilePath
                affFileList.push(affFileObj)
            }
        })

        // m += `<div class="swiper-slide box_bg area_1 swiper-no-swiping">
        //         <h4 class="public_affair_tit">${AffairsList[i].Content}</h4>
        //         <div class="affairImgWrap">
        //             <img src="${affImgList[0]}" alt="">
        //         </div>
        //         <div class="affair_file_content">
        //             <div class="public_affair_tit">附件</div>
        //             <ul class="affair_file_ul">`

        // for(var j=0;j<affFileList.length;j++){
        //     m +=  `<li><a href="${affFileList[j].FilePath}">${affFileList[j].FileName}</a></li>`
        // }
        // m +=  `</ul>
        //         </div>
        //     </div>`

        m += '<div class="swiper-slide box_bg area_1 swiper-no-swiping">'+
            '<h4 class="public_affair_tit">'+AffairsList[i].Content+'</h4>'+
            '<div class="affairImgWrap">'+
                '<img src="'+affImgList[0]+'" alt="">'+
            '</div>'+
            '<div class="affair_file_content">'+
                '<div class="public_affair_tit">附件</div>'+
                '<ul class="affair_file_ul">'

        for(var j=0;j<affFileList.length;j++){
            m += '<li><a href="'+affFileList[j].FilePath+'">'+affFileList[j].FileName+'</a></li>'
        }
        
        m += '</ul></div></div>'
    }
    $('.public_affair .swiper-wrapper').html(m);

     // 点击全屏预览，再点击收缩
    function showBig(src,k){
        $('#popup img').attr('src',src);
        var j = $(window).width()/$(window).height();
        if(j<k){
            $('#popup img').css({
                'width': '100%',
                'height': 'auto'
            })
        }else{
            $('#popup img').css({
                'width': 'auto',
                'height': '100%'
            })
        }
        $('#popup').show()
    }

    $('.affairImgWrap').click(function(event){
        event = event||window.event;
        var target = document.elementFromPoint(event.clientX, event.clientY);
        k =event.target.offsetWidth/event.target.offsetHeight
        showBig(target.src,k);
    })

    $('#popup').click(function(){
        $(this).hide()
    })

     // 轮播
     var mySwiper = new Swiper('.swiper-container', {
        // slidesPerView: 1,
        // slidesPerGroup: 1,
        // speed: 1000,
        // spaceBetween: 30,
        //freeMode: true,
        loop: true,
        // effect : 'fade',
        // fadeEffect: {
        //     crossFade: true,
        // },
        noSwiping : true,
        autoplay: 4000,
        // touchRatio:0.01,
        autoplayDisableOnInteraction:false,
        pagination: '.swiper-pagination',
        paginationClickable :true, 
        // allowTouchMove: false
    });
}
